<?php defined('IN_PHPCMS') or exit('No permission resources.'); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>地图</title>
<link type="text/css" rel="stylesheet" href="<?php echo SKIN_PATH;?>css/pc_style.css" />
<link type="text/css" rel="stylesheet" href="<?php echo SKIN_PATH;?>css/map.css" />
<style type="text/css">
body { background:white;}
</style>
</head>

<body>
<div id="loading" style="display:none"></div><div id="l-map"></div><div class="clear"></div><div style="background:white;" id="ctrlpanel"><div class="tab-tip"id="travl-method"><a href="javascript:;"id="TransitRoute"class="cur">公交</a><a href="javascript:;"id="DrivingRoute">驾车</a></div><div class="tab-con">起点：<span id="failSpan">自动定位失败，请输入起点地址（城市街名号）</span><br/><input type="text"id="l-begin"name="l-begin"size="60"/><br/>终点：<br/><input type="text"id="l-end"name="l-end"value="<?php echo $map_info['address'];?>"size="60"/>&nbsp;&nbsp;<input type="button"id="l-confirm"value="确定"/></div></div><div id="r-result" style="overflow:auto"></div>
</body>
</html>
<script type="text/javascript" src="<?php echo SKIN_PATH;?>js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.5&ak=B605c6b7d306d1119709ab461bac0fa3"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>mobile/bd_map.js"></script>
<script type="text/javascript" src="<?php echo JS_PATH;?>mobile/baiduMap.js"></script>
<script type="text/javascript">
$("#l-map").css("height",$(document).height()*0.6+"px");
var map = new BMap.Map("l-map"),transit = null,geol = false,gpsEnable = true,loadTimer,city="",TFlag=true,loc="",$lbegin = $('#l-begin'),
$lend = $('#l-end'),$method = $('#travl-method a'),$met = $('input[name=l-method]'),pEnd = new BMap.Point(<?php echo $mark_map['0'];?>, <?php echo $mark_map['1'];?>),pCenter = new BMap.Point(<?php echo $center_map['0'];?>,<?php echo $center_map['1'];?>),TransitRoute=new BMap.TransitRoute(map,{renderOptions:{map: map,panel: "r-result",enableDragging : true}}),DrivingRoute=new BMap.DrivingRoute(map,{renderOptions:{map: map,panel: "r-result",enableDragging : true}});
map.centerAndZoom( pCenter ,<?php echo $map_info['zoom'];?>);
MarkIt();
$(window).resize(function() {
	//var mh=$("#l-map").height();dh=$(document).height()*0.5;
	//$("#l-map").css("height",dh+"px");
	//$("iframe[src*=map]",window.parent.document)[0].height=document.body.scrollHeight+dh-mh;
});
$('#l-confirm').bind('click',function() {
    $('#travl-method a.cur').trigger('click')
});
$method.bind('click',function() {
    $(this).addClass('cur').siblings().removeClass();
	if($.trim($lbegin.val())!=""){
		$('#l-map').css("z-index",100);
		$('#loading').show();
		if ($(this).attr('id')=="TransitRoute"){
			transit=TransitRoute;
			//BMap.removeOverlay(DrivingRoute);
			DrivingRoute.clearResults();
		}else{
			transit=DrivingRoute;
			//BMap.removeOverlay(TransitRoute);
			TransitRoute.clearResults();
		}
		myTransit();
		loadTimer = setInterval(function() {
			if (geol) {
				$('#loading').hide();
				clearInterval(loadTimer);
				$("iframe[src*=map]",window.parent.document)[0].height=Math.min(document.documentElement.scrollHeight,document.body.scrollHeight);
			}
		},
		1000);
		
	}
});
function MarkIt(){
	map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
	var marker1 = new BMap.Marker(pEnd);  // 创建标注
	map.addOverlay(marker1);              // 将标注添加到地图中
	//marker1.setAnimation(BMAP_ANIMATION_BOUNCE);
	//创建信息窗口
	var infoWindow1 = new BMap.InfoWindow("<?php echo $map_info['address'];?>",{
				  title : "<?php echo $map_info['address_tag'];?>" , // 信息窗口标题
				  enableMessage:true,//设置允许信息窗发送短息
				  message:""
	});
	marker1.openInfoWindow(infoWindow1);
	marker1.addEventListener("click", function(){this.openInfoWindow(infoWindow1);});
}

function myTransit() {
	$("#failSpan").hide();
    geol = false;
	if (loc==""||(loc!=""&&loc==$lbegin.val())){
		var geolocation = new BMap.Geolocation();
		geolocation.getCurrentPosition(function(r) {
			if (geolocation.getStatus() == BMAP_STATUS_SUCCESS) {
				var point = new BMap.Point(r.point.lng, r.point.lat);
				transit.search(point, pEnd);
				var gc = new BMap.Geocoder();
				gc.getLocation(point,
				function(rs) {
					var addComp = rs.addressComponents;
					var myPosAddr = addComp.province + addComp.city + addComp.district + addComp.street;
					city=addComp.city;
					loc=myPosAddr;
					if ($lbegin.val() == '') $lbegin.val(myPosAddr);
				});
				geol = !geol;
			}
		},
		{
			enableHighAccuracy: true
		});
	}
	
	if (!gpsEnable){
		locToTrans();
	}else{
		setTimeout(function() {
			if (!geol) {
				gpsEnable=false;
				locToTrans();
			}
		},
		5000)
	}
}
function locToTrans(){
	$("#failSpan").html("未找到，请输入起点详细地址（城市街名号）");
	if ($lbegin.val() == '') {
		$("#failSpan").show();
		$('#loading').hide();
		$lbegin.focus();
		return
	} else {
		if ($lbegin.val()!=""&&$lbegin.val().indexOf("市")<0)$lbegin.val("成都市"+$lbegin.val());
		var myGeo = new BMap.Geocoder();
		myGeo.getPoint($lbegin.val(),
		function(point) {
			if (point) {
				transit.search(point, pEnd);
				geol = !geol;
			}else{
				$("#failSpan").show();
				$('#loading').hide();
			}
		},
		city)
	}
}
//$(function(){$("iframe[src*=map]",window.parent.document)[0].height=1000});
</script>
